let CustomFilter = {}
const baseUrl = process.env.VUE_APP_BASE_API;
CustomFilter.install = function(Vue){

		/**
			* 数值格式化
			*/
			Vue.filter('decimal', (value, scale) => {
					if(value === null || value === undefined){
						return ''
					}
			 	let str = value + '';
					if(scale == 0){
					 	return str.split(".")[0];
					}
					if(str.indexOf(".") == -1){
						str = str + ".0";
					}

					let zeroStr = (Math.pow(10, scale - 1) + '').substring(1);
					str = str + zeroStr;
					let dotPos = str.indexOf(".");
					str = str.substr(0, dotPos + scale + 1)

					return str
		});

		/**
			* 图片地址
			*/
		Vue.filter('image', (value, width, height) => {

			if(!value){
				return ''
			}

			if(value.indexOf('http') == 0){
				if(value.indexOf("?") == -1 && width && height){
					return value  + '?imageView2/1/w/'+ width + '/h/' + height;
				}


				return value;
			}

			if(value.indexOf('/static/images/') == 0){
				return value;
			}

			return  baseUrl + value;
		})








}

export default CustomFilter;
